<blockquote class="layui-elem-quote layui-text">
    请进行邮箱认证
</blockquote>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>邮箱认证</legend>
</fieldset>

<form class="layui-form">
        <div class="layui-inline">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline">
                <input type="text" id="email" value="<?php echo $uname;  ?>" readonly name="email" lay-verify="email" autocomplete="off" class="layui-input">
            </div>
        </div>
    <div class="layui-inline">
        <button class="layui-btn layui-btn-normal" id="postemail" lay-filter="postemail">获取验证码</button>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">验证码</label>
        <div class="layui-input-inline">
            <input type="text" value=""  name="emailcode" lay-verify="number" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <button class="layui-btn" lay-submit="" lay-filter="sure">确认</button>
    </div>
</form>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    var ct=60;
    var t;
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            title: function(value){
                if(value.length < 5){
                    return '标题至少得5个字符啊';
                }
            }
            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function(data){
            layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });
        //监听提交
        form.on('submit(sure)', function(data){
            var data=JSON.stringify(data.field);
            var csrfToken = $('meta[name="csrf-token"]').attr("content");
            $.post("/tools/yzmailcode",{"data":data,"_csrf":csrfToken},function (res) {
                if(res.code>0)
                {
                    layer.msg(res.messages,function () {
                        location.href=res.url;
                    });
                }else{

                    layer.msg(res.messages);
                }

            },"json");
            return false;
        });
    });
    $("#postemail").on("click",function () {
        var email=$('#email').val();
        var csrfToken = $('meta[name="csrf-token"]').attr("content");
        $.post("/tools/getmailcode",{"email":email,"_csrf":csrfToken},function (res) {
           layer.msg(res.messages);
           if(res.code==1)
           {
               timedMsg();
           }
        },"json");
        return false;
    })
    function timedMsg() {
        $('#postemail').html("");
        if(ct <= 0)
        {
            $('#postemail').attr("disabled", false);
            $('#postemail').html('获取验证码');
            clearTimeout(t);
        }else{
            $('#postemail').attr("disabled", "disabled");
            $('#postemail').html('(' + ct + ')');
            t=setTimeout(function () {
                timedMsg();
            },1000);

        }
        ct--;

    }

</script>